package com.lsl.data_bus.example;

import com.lsl.data_bus.example.data.DataBus;
import com.lsl.data_bus.example.data.MessageData;
import com.lsl.data_bus.example.data.StartingData;
import com.lsl.data_bus.example.data.StoppingData;
import com.lsl.data_bus.example.member.MessageMember;
import com.lsl.data_bus.example.member.StatusMember;

import java.time.LocalDateTime;

/**
 * description:
 *
 * @author: liushengli
 * data: 2023/1/12
 */
public class App {
    public static void main(String[] args) {
        final var bus = DataBus.getInstance();
        bus.subscribe(new StatusMember(1));
        bus.subscribe(new StatusMember(2));
        final var foo = new MessageMember("Foo");
        final var bar = new MessageMember("Bar");
        bus.subscribe(foo);
        bus.publish(StartingData.of(LocalDateTime.now()));
        bus.publish(MessageData.of("Only Foo should see this"));
        bus.subscribe(bar);
        bus.publish(MessageData.of("Foo and Bar should see this"));
        bus.unsubscribe(foo);
        bus.publish(MessageData.of("Only Bar should see this"));
        bus.publish(StoppingData.of(LocalDateTime.now()));
    }
}
